package jcore.callback;

/**
 * 测试回调接口的用法
 * @author taowei20061122@163.com
 *
 */
public class TestCallback {
	A2 likejdbcTemplate = new A2();
	
	public void execute() {
		likejdbcTemplate.doMyJob(new SomeCallback());
	}
	
	//实现回调接口的内部类，执行具体的任务
	class SomeCallback implements Callback {
		public void doJob() {
			//do some thing
			System.out.println("SomeCallback....");
		}
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		A a = new A(new Callback(){ //implement interface 's method.
						public void doJob() {
							System.out.println(" do something...");
						}
					}
		);
		a.setSomethingHappend();
		a.doMyJob();
		
		B b1 = new B();
		Callback b2 = new B();
		
		
		A a1 = new A(b1); //callback or b ?  have something different ?
		A a2 = new A(b2);
		a1.setSomethingHappend();
		a2.setSomethingHappend();
		
		a1.doMyJob();
		a2.doMyJob();
		
		new TestCallback().execute();
		
	}

}
